package com.wuye.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.wuye.VO.BaseCommunityVo;
import com.wuye.VO.YiBiaoVo;
import com.wuye.basic.domain.WyCommunity;
import com.wuye.domain.WyYbType;
import com.wuye.dto.YibiaoAddDto;
import com.wuye.dto.YibiaoSerchDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.wuye.common.annotation.Log;
import com.wuye.common.core.controller.BaseController;
import com.wuye.common.core.domain.AjaxResult;
import com.wuye.common.enums.BusinessType;
import com.wuye.domain.WyYibiao;
import com.wuye.service.IWyYibiaoService;
import com.wuye.common.utils.poi.ExcelUtil;
import com.wuye.common.core.page.TableDataInfo;

/**
 * 仪表管理Controller
 * 
 * @author jack
 * @date 2024-11-22
 */
@RestController
@RequestMapping("/yibiaoManagement/yibiao")
public class WyYibiaoController extends BaseController
{
    @Autowired
    private IWyYibiaoService wyYibiaoService;

    /**
     * 查询仪表管理列表
     */
    @PreAuthorize("@ss.hasPermi('yibiaoManagement:yibiao:list')")
    @GetMapping("/list")
    public TableDataInfo list(YibiaoSerchDto yibiaoSerchDto)
    {
        startPage();
        List<YiBiaoVo> yiBiaoVos = wyYibiaoService.selectWyYibiaoList2(yibiaoSerchDto);
        return getDataTable(yiBiaoVos);
    }

    /**
     * 导出仪表管理列表
     */
    @PreAuthorize("@ss.hasPermi('yibiaoManagement:yibiao:export')")
    @Log(title = "仪表管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WyYibiao wyYibiao)
    {
        List<WyYibiao> list = wyYibiaoService.selectWyYibiaoList(wyYibiao);
        ExcelUtil<WyYibiao> util = new ExcelUtil<WyYibiao>(WyYibiao.class);
        util.exportExcel(response, list, "仪表管理数据");
    }

    /**
     * 获取仪表管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('yibiaoManagement:yibiao:query')")
    @GetMapping(value = "/{ybId}")
    public AjaxResult getInfo(@PathVariable("ybId") Long ybId)
    {
        return success(wyYibiaoService.selectWyYibiaoByYbId(ybId));
    }

//    /**
//     * 新增仪表管理
//     */
//    @PreAuthorize("@ss.hasPermi('yibiaoManagement:yibiao:add')")
//    @Log(title = "仪表管理", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody WyYibiao wyYibiao)
//    {
//        return toAjax(wyYibiaoService.insertWyYibiao(wyYibiao));
//    }


    /**
     * 新增仪表管理
     */
    @PreAuthorize("@ss.hasPermi('yibiaoManagement:yibiao:add')")
    @Log(title = "仪表管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YibiaoAddDto yibiaoAddDto)
    {
        return toAjax(wyYibiaoService.insertWyYibiao(yibiaoAddDto));
    }

    /**
     * 修改仪表管理
     */
    @PreAuthorize("@ss.hasPermi('yibiaoManagement:yibiao:edit')")
    @Log(title = "仪表管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WyYibiao wyYibiao)
    {
        return toAjax(wyYibiaoService.updateWyYibiao(wyYibiao));
    }

    /**
     * 删除仪表管理
     */
    @PreAuthorize("@ss.hasPermi('yibiaoManagement:yibiao:remove')")
    @Log(title = "仪表管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ybIds}")
    public AjaxResult remove(@PathVariable Long[] ybIds)
    {
        return toAjax(wyYibiaoService.deleteWyYibiaoByYbIds(ybIds));
    }


    /**
     * 查询小区列表
     */
    @PreAuthorize("@ss.hasPermi('yibiaoManagement:yibiao:list')")
    @GetMapping("/communitylist")
    public TableDataInfo communitylist()
    {
        List<WyCommunity> list=wyYibiaoService.seleceAllCommunity();
        return getDataTable(list);
    }


    /**
     * 查询类型列表
     */
    @PreAuthorize("@ss.hasPermi('yibiaoManagement:yibiao:list')")
    @GetMapping("/typelist")
    public TableDataInfo typelist()
    {
        List<WyYbType> list=wyYibiaoService.selectAllType();
        return getDataTable(list);
    }


    /**
     * 修改仪表状态
     * @param id
     * @return
     */
    @PreAuthorize("@ss.hasPermi('yibiaoManagement:yibiao:edit')")
    @Log(title = "仪表管理", businessType = BusinessType.UPDATE)
    @PutMapping("/editStatus/{id}")
    public AjaxResult editStatus(@PathVariable Long id)
    {
        Integer num=wyYibiaoService.updateStatus(id);
        return toAjax(num);
    }


    /**
     * 查询小区、楼座、单元、房间列表
     */
    @PreAuthorize("@ss.hasPermi('yibiaoManagement:yibiao:list')")
    @GetMapping("/communityAndBUH")
    public TableDataInfo communityAndBUH()
    {
        ArrayList<BaseCommunityVo> baseCommunityVos = new ArrayList<>();
        BaseCommunityVo baseCommunityVo = wyYibiaoService.selectAllcommunityAndBUH();
        baseCommunityVos.add(baseCommunityVo);
        return getDataTable(baseCommunityVos);
    }



    /**
     * 抄表
     */
//    @PreAuthorize("@ss.hasPermi('charge:allocation:add')")

//    @PreAuthorize("@ss.hasPermi('yibiaoManagement:yibiao:edit')")
    @Log(title = "仪表管理", businessType = BusinessType.UPDATE)
    @PutMapping("chaobiao/{id}")
    public AjaxResult chaobiao(@PathVariable Long id)
    {
        return toAjax(wyYibiaoService.chaobiao(id));
    }


}
